/*
* berton
*/
package com.pitop.material.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.material.entity.Material;
import com.pitop.material.service.MaterialSV;

/**
* 供应料材 控制器
*
* @author berton
*/
@RestController
@RequestMapping("/material")
@Slf4j
@Api(value = "供应料材控制器", description = "供应料材控制器")
public class MaterialCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MaterialSV materialSV;

    /**
    * 查询Material一个详情信息
    * @param id 
    * @param code 编码
    * @param suppierCode 供应商编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Material一个详情信息", notes = "查询Material一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "query"),
        @ApiImplicitParam(name = "suppierCode", value = "供应商编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public Material load(java.lang.Long id,java.lang.String code,java.lang.String suppierCode) {
        if(id==null){
        return null;
        }
        if(code==null){
        return null;
        }
        if(suppierCode==null){
        return null;
        }
        Material material = materialSV.load(id,code,suppierCode);
        log.info(JSON.toJSONString(material));
        return material;
    }


    /**
    * 根据条件id查询Material一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Material一个详情信息", notes = "查询Material一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public Material loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        Material material = materialSV.loadById(id);
        log.info(JSON.toJSONString(material));
        return material;
    }
    /**
    * 根据条件code查询Material一个详情信息
    *
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Material一个详情信息", notes = "查询Material一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public Material loadByCode(@PathVariable java.lang.String code) {
        if(code==null){
           return null;
        }
        Material material = materialSV.loadByCode(code);
        log.info(JSON.toJSONString(material));
        return material;
    }
    /**
    * 根据条件suppierCode查询Material一个详情信息
    *
    * @param suppierCode 供应商编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Material一个详情信息", notes = "查询Material一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "suppierCode", value = "供应商编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/suppierCode/{suppierCode}")
    @ResponseBody
    public Material loadBySuppierCode(@PathVariable java.lang.String suppierCode) {
        if(suppierCode==null){
           return null;
        }
        Material material = materialSV.loadBySuppierCode(suppierCode);
        log.info(JSON.toJSONString(material));
        return material;
    }


    /**
    * 查询Material信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Material信息集合", notes = "查询Material信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
        @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTimeBegin", value = "更新时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTimeEnd", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<Material> list(@RequestBody @ApiIgnore Material material,Integer curPage,Integer pageSize) {
        Page<Material> page=new Page<Material>(pageSize,curPage);
        List<Material> materials = materialSV.list(material,page.genRowStart(),page.getPageSize());
        int total = materialSV.count(material);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return materials;
    }


    /**
    * 查询Material信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Material信息集合", notes = "查询Material信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
    @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<Material> listByPk(java.lang.Long id,java.lang.String code,java.lang.String suppierCode,Integer curPage,Integer pageSize) {
        Page<Material> page=new Page<Material>(pageSize,curPage);
        List<Material> materials = materialSV.list(id,code,suppierCode, page.genRowStart(),page.getPageSize());
        int total = materialSV.count(id,code,suppierCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return materials;
    }

    /**
    * 统计Material信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计Material信息数量根据主键", notes = " 统计Material信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
    @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String code,java.lang.String suppierCode) {
        return materialSV.count(id,code,suppierCode);
    }

    /**
    * 统计Material信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计Material信息数量", notes = "统计Material信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
    @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
    @ApiImplicitParam(name = "num", value = "编号", paramType = "query"),
    @ApiImplicitParam(name = "name", value = "名称", paramType = "query"),
    @ApiImplicitParam(name = "specifications", value = "规格 厘米，克等计量单位", paramType = "query"),
    @ApiImplicitParam(name = "brandCode", value = "品牌编码", paramType = "query"),
    @ApiImplicitParam(name = "materialCategoryCode", value = "材料类型编码", paramType = "query"),
    @ApiImplicitParam(name = "imageUrl", value = "图片地址", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "描述 64个汉字描述", paramType = "query"),
    @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable", paramType = "query"),
    @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
    @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody Material material) {
        if(material==null){
            return materialSV.count(new HashMap());
        }else{
            return materialSV.count(material);
        }
    }



    /**
    * 创建Material
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建Material", notes = "创建Material")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "num", value = "编号", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "名称", paramType = "query"),
        @ApiImplicitParam(name = "specifications", value = "规格 厘米，克等计量单位", paramType = "query"),
        @ApiImplicitParam(name = "brandCode", value = "品牌编码", paramType = "query"),
        @ApiImplicitParam(name = "materialCategoryCode", value = "材料类型编码", paramType = "query"),
        @ApiImplicitParam(name = "imageUrl", value = "图片地址", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "描述 64个汉字描述", paramType = "query"),
        @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable", paramType = "query"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public Material build(@RequestBody @ApiIgnore Material material) {
        materialSV.save(material);
        return material;
    }


    /**
    * 修改Material
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改Material", notes = "修改Material")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
        @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
        @ApiImplicitParam(name = "num", value = "编号", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "名称", paramType = "query"),
        @ApiImplicitParam(name = "specifications", value = "规格 厘米，克等计量单位", paramType = "query"),
        @ApiImplicitParam(name = "brandCode", value = "品牌编码", paramType = "query"),
        @ApiImplicitParam(name = "materialCategoryCode", value = "材料类型编码", paramType = "query"),
        @ApiImplicitParam(name = "imageUrl", value = "图片地址", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "描述 64个汉字描述", paramType = "query"),
        @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable", paramType = "query"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public Material modify(@ApiIgnore Material material) {
        materialSV.modify(material);
        return material;
    }

    /**
    * 删除Material
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除Material", notes = "删除Material")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
        @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code,java.lang.String suppierCode) {
        materialSV.delete(id,code,suppierCode);
        return BeanRet.create(true, "删除Material成功");
    }

}
